package com.gewu.ordlelist.activity;

import androidx.annotation.NonNull;
import androidx.appcompat.app.AppCompatActivity;
import androidx.appcompat.widget.Toolbar;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.bumptech.glide.load.resource.bitmap.RoundedCorners;
import com.bumptech.glide.request.RequestOptions;
import com.gewu.ordlelist.R;
import com.gewu.ordlelist.base.BaseActivity;
import com.gewu.ordlelist.database.dbbean.footers;
import com.gewu.ordlelist.database.dbdao.footerDao;
import com.gewu.ordlelist.utils.jocUtils;

import java.util.List;
import java.util.Random;

public class mian extends BaseActivity {


    private Toolbar toolbar;
    private android.widget.TextView text;
    private androidx.recyclerview.widget.RecyclerView rec;

    @Override
    public int FindLayout() {
        return R.layout.activity_mian;
    }

    @Override
    public Toolbar getToolBar() {
        return toolbar;
    }

    @Override
    public boolean isShowBackToolbar() {
        return true;
    }

    @Override
    public String setToolbarText() {
        return "已下单";
    }

    @Override
    public void initview() {
        toolbar = findViewById(R.id.toolbar);
        text = findViewById(R.id.text);
        rec = findViewById(R.id.rec);

        toolbar.setTitle(setToolbarText());

        List<footers> quer = new footerDao(this).quer();
        rec.setLayoutManager(new LinearLayoutManager(this, LinearLayoutManager.VERTICAL, false));
        rec.setAdapter(new RecyclerView.Adapter() {

            @NonNull
            @Override
            public RecyclerView.ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
                View inflate = LayoutInflater.from(parent.getContext()).inflate(R.layout.four_item, parent, false);
                return new fourItem(inflate);
            }

            @Override
            public void onBindViewHolder(@NonNull RecyclerView.ViewHolder holder, int position) {
                RoundedCorners roundedCorners = new RoundedCorners(50);
                RequestOptions options = RequestOptions.bitmapTransform(roundedCorners);
                int i = new Random().nextInt(6);
                Glide.with(holder.itemView).load(jocUtils.getimgs()[i]).apply(options).into(((fourItem) holder).image);
                ((fourItem) holder).text.setText(quer.get(position).getName() + "\t价格：" + quer.get(position).getMoney());
                ((fourItem) holder).text2.setText(R.string.text);
                ((fourItem) holder).ok.setVisibility(View.GONE);
            }

            @Override
            public int getItemCount() {
                return quer.size();
            }
        });
    }

    private class fourItem extends RecyclerView.ViewHolder {

        private TextView text2;
        private TextView text;
        private ImageView image;
        private TextView ok;

        public fourItem(View inflate) {
            super(inflate);
            image = inflate.findViewById(R.id.image);
            text = inflate.findViewById(R.id.text);
            text2 = inflate.findViewById(R.id.text2);
            ok = inflate.findViewById(R.id.ok);
        }
    }

}